part of 'alert.dart';

///加载中loading
class AlertLoading extends StatefulWidget {
  const AlertLoading({Key? key}) : super(key: key);

  @override
  State<AlertLoading> createState() => _AlertLoadingState();
}

void showLoading({
  bool barrierDismissible = false,
  Duration? duration,
}) {
  Get.dialog(AlertLoading(), barrierDismissible: barrierDismissible);
  if (duration != null) {
    Future.delayed(duration, () => Get.back());
  }
}

void hideLoading() => Get.back();

class _AlertLoadingState extends State<AlertLoading>
    with SingleTickerProviderStateMixin {
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();

    //图片旋转动画
    _controller =
        AnimationController(vsync: this, duration: Duration(seconds: 5))
          ..addStatusListener((status) {
            if (status == AnimationStatus.completed) {
              _controller.reset();
              _controller.forward();
            }
          })
          ..forward();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return UnconstrainedBox(
        child: Material(
      color: Colors.transparent,
      child: Container(
        height: 220,
        width: 160,
        child: Column(
          children: [
            RotationTransition(
              turns: _controller,
              child: Stack(
                alignment: Alignment.center,
                children: ['loading_circle'.uiimg, 'loading_logo'.uiimg],
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 10),
              child: Text(
                'Uploading......',
                style: TextStyle(
                    color: Theme.of(context).primaryColor, fontSize: 18),
              ),
            ),
          ],
        ),
      ),
    ));
  }
}
